package com.google.bling.client;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Util {
  public static <T> List<T> list(T... ts) {
    ArrayList<T> result = new ArrayList<T>();
    for (T t : ts) {
      result.add(t);
    }
    return result;
  }

  public static boolean isNumber(String text) {
    try {
      Integer.parseInt(text);
      return true;
    } catch (NumberFormatException e) {
      return false;
    }
  }

  public static String removeQuotes(String s) {
    return s.substring(1, s.length() - 1);
  }

  public static int parseInt(String text) {
    if (text.length() == 0) {
      return 0;
    }
    return Integer.parseInt(text);
  }

  public static <K, V> Map<K, V> makeHash(List<K> keys, List<V> values) {
	HashMap<K, V> result = new HashMap<K, V>();
	for (int i = 0; i < keys.size(); i++) {
      result.put(keys.get(i), values.get(i));
	}
	return result;
  }

  public static <K> String join(List<K> strs, String delimiter) {
    String result = "";
    String delim = "";
    for (K k : strs) {
      result += (delim + k);
      delim = delimiter;
    }
    return result;
  }
}
